import request from '@/utils/request';
import qs from 'qs';
import type { PageResult, ResponseData } from '../typing';
// 参数接口
export interface UpdateProjectRelationParams {
    // 项目code */
    projectCode: string;
    // 关联项目code列表 */
    relationProjectCodes: Record<string, unknown>[];
}

/**
 * 更新项目关联
 * @param {object} params 管理后台 - 项目关联更新 Request VO
 * @param {string} params.projectCode 项目code
 * @param {array} params.relationProjectCodes 关联项目code列表
 * @returns
 */
export function updateProjectRelation(params: UpdateProjectRelationParams): Promise<ResponseData<boolean>> {
    return request.put(`/yfwy/project-relation/update`, params);
}
// 参数接口
export interface CreateProjectRelationParams {
    // 项目code */
    projectCode: string;
    // 关联项目code列表 */
    relationProjectCodes: Record<string, unknown>[];
}

/**
 * 创建项目关联
 * @param {object} params 管理后台 - 项目关联创建 Request VO
 * @param {string} params.projectCode 项目code
 * @param {array} params.relationProjectCodes 关联项目code列表
 * @returns
 */
export function createProjectRelation(params: CreateProjectRelationParams): Promise<ResponseData<boolean>> {
    return request.post(`/yfwy/project-relation/create`, params);
}
export interface ProjectRelationsParams {
    projectCode: string;
    current: number;
    size: number;
}
// 响应接口
export interface GetProjectRelationPageRes {
    code: number;
    data: {
        size: number;
        total: number;
        records: {
            // 项目名称 */
            projectName: string;
            // 项目code */
            projectCode: string;
            // 关联项目名称 */
            relationProjectNames: string;
        }[];
        current: number;
        pages: number;
    };
    msg: string;
}
/**
 * 获得项目关联分页
 * @param {string} projectCode 项目树code
 * @param {string} current 当前第几页(默认1)
 * @param {string} size 每页条数(默认20)
 * @returns
 */
export function getProjectRelationPage(params: ProjectRelationsParams): Promise<GetProjectRelationPageRes> {
    return request.get(`/yfwy/project-relation/page?${qs.stringify(params)}`);
}
// 响应接口
export interface GetProjectRelationRes {
    code: number;
    data: {
        // 项目名称 */
        projectName: string;
        // 项目code */
        projectCode: string;
        // 关联项目code列表 */
        relationProjectCodes: Record<string, unknown>[];
    };
    msg: string;
}
/**
 * 获得项目关联
 * @param {string} projectCode 项目code
 * @returns
 */
export function getProjectRelation(projectCode: string): Promise<GetProjectRelationRes> {
    return request.get(`/yfwy/project-relation/get/${projectCode}`);
}
/**
 * 导出项目关联 Excel
 * @param {string} projectCode 项目树code
 * @param {string} current 当前第几页(默认1)
 * @param {string} size 每页条数(默认20)
 * @returns
 */
export function exportProjectRelationExcel(params: ProjectRelationsParams): Promise<Blob> {
    return request.get(`/yfwy/project-relation/export-excel?${qs.stringify(params)}`, { responseType: 'blob' });
}
/**
 * 删除项目关联
 * @param {string} projectCode 项目code
 * @returns
 */
export function deleteProjectRelation(projectCode: string): Promise<ResponseData<boolean>> {
    return request.delete(`/yfwy/project-relation/delete/${projectCode}`);
}
